<template>
	<view class="">
		<view class="pl-20 pr-20 bg-white">
			<u-search placeholder="搜索" v-model="searchData.name" :showAction="false" @search="onSearch" />
		</view>
		<view class="padding-10 bg-white">
			<u-tabs lineColor="#e54d42" :activeStyle="{'color':'#e54d42'}" keyName="label" :list="subsectionList" @click="sectionChange" />
		</view>
		<view class="my-list">
			<u-list :height="swiperHeight" @scrolltolower="scrolltolower" v-if="dataList.length > 0">
				<u-list-item v-for="(item, index) in dataList" :key="index">
					<view class="item flex justify-between align-center" @click="$u.route('/pages/finance/stockDetails?id='+item.id)">
						<view class="flex flex--row">
							<view class="flex align-center">
								<text>{{item.remark}}</text>
								<view class="ml-10 fsize-20 pt-2 pb-2 bg-red pl-10 pr-10 border-radius-tr-6 border-radius-tl-6">{{item.directionText}}</view>
							</view>
							<text class="mt-20 line-gray fsize-26">{{item.userName}} | {{item.createTime}}</text>
						</view>
						<view>
							<!-- <text class="fsize-24">{{item.direction===1?'+':''}}</text> -->
							<text>{{item.amount}}</text>
						</view>
					</view>
				</u-list-item>
				<u-loadmore 
					:status="loadmore.status" 
					:icon-type="loadmore.iconType" 
					:load-text="loadmore.loadText.loadText" 
					margin-top="40"
					margin-bottom="20" 
					class="coreshop-padding-top-10" 
				/>
			</u-list>
		</view>
		<!-- 无数据时默认显示 -->
		<view class="emptybox" v-if="dataList.length == 0">
			<u-empty icon-size="150" text="暂无数据" mode="data"></u-empty>
		</view>
	</view>
</template>

<script>
	import listHeightMixin from '@/common/computedAltitude.js'
	export default {
		mixins:[listHeightMixin],
		data() {
			return {
				subsectionList: [
					{ label: '全部', value: '0' }, 
					{ label: '入账', value: '1' },
					{ label: '出账', value: '-1' },
				],
				loadmore:{
					status: 'loadmore',
					iconType: 'flower',
					loadText: {
						loadmore: '轻轻上拉',
						loading: '努力加载中',
						nomore: '实在没有了'
					},
				},
				curNow: 0,
				staffId:0,
				dataList: [],
				searchData: {
					name:'',
					direction:0,
					page: 1,
					limit: 10,
					staffId:0,
				}
			}
		},
		onLoad(option) {
			console.log(option)
			let that = this
			if (option.id) {
				uni.setNavigationBarTitle({ title: `${option.userName}的股本记录` })
				this.staffId = option.id
				this.searchData.staffId=this.staffId
				this.getPageList(this.staffId)
			}else{
				this.getPageList(0)
			}
		},
		methods: {
			onSearch(val){
				this.dataList = []
				this.searchData.page = 1
				this.getPageList()
			},
			sectionChange(e) {
				if (this.curNow === e.index) return
				this.curNow = e.index
				this.searchData = this.$options.data().searchData
				this.searchData.direction = e.value
				if(this.staffId){
					this.searchData.staffId = this.staffId
				}
				this.searchData.page = 1
				this.dataList = []
				this.getPageList()
			},
			getPageList(staffId) {
				this.$reqPost('CoreCmsStoreStaffStockGetPageList', this.searchData).then(res => {
					this.dataList = [...this.dataList, ...res.data]
					if (res.count > this.dataList.length) {
						this.loadmore.status = 'loadmore'
						this.searchData.page++
					} else {
						// 数据已加载完毕
						this.loadmore.status = 'nomore'
					}
				})
			},
			scrolltolower() {
				if (this.loadmore.status === 'loadmore') {
					this.getPageList()
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.fontWeightNormal{ font-weight: normal;}
	.paddingTop20{ padding-top: 20rpx;}
</style>
